package com.wjw.java.juc;

import lombok.extern.slf4j.Slf4j;

/**
 * Runnable接口,推荐使用implements Runnable接口的方式,Java可以实现多个接口
 */
@Slf4j(topic = "c._02Runnable")
public class _02Runnable {

    public static void main(String[] args) {
        test1();
        test2();
        log.debug("主线程...");
    }

    /**
     * 使用Runnable写法
     */
    public static void test1(){
                         //鼠标选中Runnable,alt + enter,选中replace with lambda,idea会简化为lambda表达式写法
        Runnable run = new Runnable() {
            @Override
            public void run() {
                log.debug("test1...");
            }
        };

        Thread t1 = new Thread(run,"t1");
        t1.start();
    }

    /**
     * 使用Runnable写法,简化版
     */
    public static void test2(){
        //lambda表达式方法体中如果只有一行代码,可以省略首位的{}
        Runnable run2 = () -> log.debug("test2...");
        Thread t2 = new Thread(run2,"t2");
        t2.start();
    }
}
